package com.lbn.baseframe.image;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.DrawableRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

/**
 * Created by Administrator on 2016/6/22.
 */
public class LoaderImage {


    private LoaderImage() {

    }

    public static DrawableRequestBuilder<String> loaderImage(String url, final ImageView imageView, int error, int placeholder) {

        DrawableRequestBuilder<String> build = Glide.with(imageView.getContext())
                .load(url)
                .error(android.R.mipmap.sym_def_app_icon)
                .fitCenter()
                .diskCacheStrategy(DiskCacheStrategy.RESULT)
                .crossFade();

        if (placeholder != 0)
            build.placeholder(placeholder);

        if (error != 0)
            build.error(error);

        return build;
    }

    public static DrawableRequestBuilder<String> loader(String url, ImageView imageView, int error, int placeholder) {
        return loaderImage(url, imageView, error, placeholder);
    }

//    public static void loaderRoundedImage(final String url, final ImageView imageView,int error,int placeholder){
//        loader(url,imageView,error,placeholder).transform(new GlideRoundTransform(imageView.getContext(),5)).into(imageView);
//    }

//    public static void loaderRoundedImage(final String url, final ImageView imageView){
//        loaderRoundedImage(url,imageView,0,0);
//    }

    public static void displayImage(String url, ImageView imageView, int error, int placeholder) {
        loader(url, imageView, error, placeholder).into(imageView);
    }

    public static void displayImage(String url, ImageView imageView) {
        displayImage(url, imageView, 0, 0);
    }

}
